package wangjg.mda.context;

import java.io.File;

import wangjg.mda.lang.CodeTX;
import wangjg.mda.model.obj.Model;

/**
 * 
 * @author wangjg
 *
 */
public class SourceContext extends FileSystemModelContext {
	
	public Model loadModel(File file){
		CodeTX cp = new CodeTX();
		cp.loadSource(file.getPath(), this.getCharset());
		Model model = cp.getModel();
		return model;
	}
	
	protected File getFile(String name){
		for(String dir : this.getDirList()){
			String SP = File.separator;
			if("\\".equals(SP)){
				SP = "\\\\";
			}
			String sPath = name.replaceAll("\\.", SP);
			File file = new File(dir,sPath+".java");
			if(file.exists()&&file.isFile()&&file.canRead()){
				return file;
			}
		}
		return null;
	}
	
}
